import javax.swing.plaf.synth.SynthOptionPaneUI;

// 这样会出现死锁现象
public class ThreadDemo17 {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        Thread t1 = new Thread(() ->{
           synchronized (A){
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               synchronized (B){//尝试给B加锁
                   System.out.println("t1 拿到了两把锁");
               }
           }
        });
        Thread t2 = new Thread(() ->{
            synchronized (B){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (A){ //尝试给A加锁
                    System.out.println("t2 拿到了两把锁");
                }
            }
        });
    }
}
